//
//  WPPrivateInfoTableViewCell.m
//  wobingwoyi
//
//  Created by WGP on 16/9/7.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPPrivateInfoTableViewCell.h"
#import "WPInfomationModel.h"

@interface WPPrivateInfoTableViewCell ()

@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UIView *privateContentView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *contentLabel;
@property(nonatomic,strong)MASConstraint  *heightConstraint;

@end
@implementation WPPrivateInfoTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.backgroundColor = GlobalBgColor;
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    [self timeLabel];
    [self iconView];
    [self nameLabel];
    [self privateContentView];
    [self titleLabel];
    [self contentLabel];
}

-(UILabel *)timeLabel
{
    if (_timeLabel == nil)
    {
        _timeLabel = [UILabel new];
        _timeLabel.font = [UIFont systemFontOfSize:11];
        _timeLabel.textColor = GloballightFontColor;
        _timeLabel.text = @"09月04日 21:23";
        [_timeLabel sizeToFit];
        [self.contentView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(25);
            make.centerX.equalTo(self.contentView);
        }];
    }
    return _timeLabel;
}

-(UIImageView *)iconView
{
    if (_iconView == nil)
    {
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"privateInfo_system"]];
        [_iconView sizeToFit];
        [self.contentView addSubview:_iconView];
        
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(10);
            make.top.equalTo(self.contentView).offset(45);
            make.width.height.mas_equalTo(40);
        }];
    }
    return _iconView;
}

-(UILabel *)nameLabel
{
    if (_nameLabel == nil)
    {
        _nameLabel = [UILabel new];
        _nameLabel.font = [UIFont systemFontOfSize:11];
        _nameLabel.textColor = RGB_SAME(102);
        _nameLabel.text = @"我病我医";
        [self.contentView addSubview:_nameLabel];
        
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconView);
            make.left.equalTo(self.iconView.mas_right).offset(10);
        }];
    }
    return _nameLabel;
}

-(UIView *)privateContentView
{
    if (_privateContentView == nil)
    {
        _privateContentView = [UIView new];
        _privateContentView.backgroundColor = [UIColor whiteColor];
        _privateContentView.layer.cornerRadius = 4;
        _privateContentView.layer.masksToBounds = YES;
        [self.contentView addSubview:_privateContentView];
        
        [_privateContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.nameLabel);
            make.top.equalTo(self.nameLabel.mas_bottom).offset(6);
            make.right.equalTo(self.contentView).offset(-15);
            make.bottom.equalTo(self.contentView);
        }];
    }
    return _privateContentView;
}

-(UILabel *)titleLabel
{
    if (_titleLabel == nil)
    {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = RGB_SAME(102);
        [self.privateContentView addSubview:_titleLabel];
        [_titleLabel sizeToFit];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self.privateContentView).offset(10);
        }];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel
{
    if (_contentLabel == nil)
    {
        _contentLabel = [UILabel new];
        _contentLabel.font = [UIFont systemFontOfSize:13];
        _contentLabel.textColor = RGB_SAME(102);
        _contentLabel.numberOfLines = 0;
        [_contentLabel sizeToFit];
        [self.privateContentView addSubview:_contentLabel];
        
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
            make.left.equalTo(self.titleLabel);
            make.right.equalTo(self.privateContentView).offset(-10);
            make.bottom.equalTo(self.privateContentView).offset(-18);
        }];
    }
    return _contentLabel;
}

-(void)setModel:(WPInfomationModel *)model
{
    _model = model;
    
    self.timeLabel.text = model.time;
    self.titleLabel.text = model.title;
    
//    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
//    paraStyle.lineSpacing = UILABEL_LINE_SPACE; //设置行间距
//    
//    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paraStyle};
//    
//    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:model.content attributes:dic];
//    self.contentLabel.attributedText = attributeStr;
    self.contentLabel.text = model.content;
}

@end

















